package com.nightsoul.shirotest.jdbc;

import org.springframework.jdbc.core.JdbcTemplate;

import com.alibaba.druid.pool.DruidDataSource;

public class JdbcTemplateUtils {
	private static volatile JdbcTemplate jdbcTemplate;

	public static JdbcTemplate getJdbcTemplate() {
		if(jdbcTemplate == null) {
			synchronized (JdbcTemplateUtils.class) {
				if(jdbcTemplate == null) {
					jdbcTemplate = createJdbcTemplate();
				}
			}
		}
		return jdbcTemplate;
	}

	private static JdbcTemplate createJdbcTemplate() {
		DruidDataSource ds = new DruidDataSource();
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUrl("jdbc:mysql://localhost:3306/shiro-test");
        ds.setUsername("root");
        ds.setPassword("xtayfjpk");
        return new JdbcTemplate(ds);
	}
}
